import type PaymentHistory from "@/types/response/paymentHistory";
import  ResUtil  from "@/utils/resUtil";
import axiosManager from "../axiosManager";

const instance = axiosManager.caseAxios;

/**
 * 增加还款记录反馈
 */
async function createPaymentHistory(paymentHistory: PaymentHistory) {
    let res = await instance.post("/paymentHistory", paymentHistory);
    return ResUtil.isSuccess(res);
}
//获得待调解员审批的还款记录

/**
 * 调解员审批还款记录
 */
async function examinePaymentHistoryReq(paymentHistoryId: number,flag:number) {
    let res = await instance.put("/paymentHistory/examine", null,{
        params:{
            paymentHistoryId,
            flag
        
    }});
    return ResUtil.isSuccess(res);
}
async function getPaymentWaitExamine(mediatorId:number){
    let res=await instance.get("/paymentHistory/examine",{
        params:{
            mediatorId
        }
    });
    return ResUtil.getData<PaymentHistory[]>(res);
}
/**
 * 通过案件id获得还款记录
 */
async function getPaymentHistoryByCase(caseId: number) {
    let res = await instance.get("/paymentHistory", {
        params: { caseId }
    });
    if (ResUtil.isSuccess(res)) {
        return ResUtil.getData<PaymentHistory[]>(res);
    }
    return null;
}

export {
    createPaymentHistory,
    examinePaymentHistoryReq,
    getPaymentHistoryByCase,
    getPaymentWaitExamine
};